package bb.lanxing.lib.devices.ble.device;

//import com.alipay.sdk.authjs.a;
//import com.alipay.sdk.packet.d;
import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.ble.battery.BatteryController;
import bb.lanxing.lib.devices.ble.ble.base.BaseBleSensorDevice;
import bb.lanxing.lib.devices.ble.ble.base.BaseResponsiveCharacteristic;
import bb.lanxing.lib.devices.ble.ble.characteristic.BatteryStatus;
import bb.lanxing.lib.devices.ble.ble.characteristic.BatteryStatusCharacteristic;
import bb.lanxing.lib.devices.ble.ble.characteristic.light.LightBeamMode;
import bb.lanxing.lib.devices.ble.ble.characteristic.light.LightControlPointOpCode;
import bb.lanxing.lib.devices.ble.ble.characteristic.light.LightControlPointRequest;
import bb.lanxing.lib.devices.ble.ble.characteristic.light.LightControlPointResult;
import bb.lanxing.lib.devices.ble.ble.characteristic.light.LightMachineStatus;
import bb.lanxing.lib.devices.ble.ble.characteristic.light.LightMachineStatusCharacteristics;
import bb.lanxing.lib.devices.ble.ble.characteristic.light.LightMode;
import bb.lanxing.lib.devices.ble.ble.services.BatteryService;
import bb.lanxing.lib.devices.ble.ble.services.DisBleService;
import bb.lanxing.lib.devices.ble.ble.services.LightService;
import bb.lanxing.lib.devices.ble.ble.services.RadarService;
import bb.lanxing.lib.devices.ble.light.LightDeviceController;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import kotlin.UByte;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;
import kotlinx.coroutines.flow.MutableStateFlow;
/* compiled from: LightDevice.kt */

public final class LightDevice extends BaseBleSensorDevice implements LightDeviceController, BatteryController {
    private final BatteryService batteryService;
    private final DisBleService disBleService;
    private final LightService lightService;
    private final RadarService radarService;

    public LightDevice(SmartDevice device) {
        super(device);
        Intrinsics.checkNotNullParameter(device, "device");
        LightDevice lightDevice = this;
        this.disBleService = new DisBleService(lightDevice);
        this.batteryService = new BatteryService(lightDevice);
        this.lightService = new LightService(lightDevice);
        this.radarService = new RadarService(lightDevice);
    }

    public DisBleService getDisBleService() {
        return this.disBleService;
    }

    public BatteryService getBatteryService() {
        return this.batteryService;
    }

    public LightService getLightService() {
        return this.lightService;
    }

    public RadarService getRadarService() {
        return this.radarService;
    }

    public boolean sendRequest(LightControlPointRequest lightControlPointRequest) {
//        Intrinsics.checkNotNullParameter(lightControlPointRequest, "lightControlPointRequest");
        BaseResponsiveCharacteristic lightControlPointResponsiveCharacteristics = this.lightService.getLightControlPointResponsiveCharacteristics();
        if (lightControlPointResponsiveCharacteristics != null) {
            return lightControlPointResponsiveCharacteristics.sendRaw(lightControlPointRequest.convertByteArray());
        }
        return false;
    }

    public void executeRequest(LightControlPointRequest lightControlPointRequest, Function1<? super LightControlPointResult, Unit> callBack) {
        Intrinsics.checkNotNullParameter(lightControlPointRequest, "lightControlPointRequest");
        Intrinsics.checkNotNullParameter(callBack, "callBack");
        BaseResponsiveCharacteristic lightControlPointResponsiveCharacteristics = this.lightService.getLightControlPointResponsiveCharacteristics();
        if (lightControlPointResponsiveCharacteristics != null) {
//            BaseResponsiveCharacteristic.executeRaw$default(lightControlPointResponsiveCharacteristics, lightControlPointRequest.convertByteArray(), new LightDevice$executeRequest$1(callBack, null), null, 4, null);
        }
    }

    @Override
    public boolean isInitDone() {
        return getInitializationState();
    }

    @Override
    public boolean readLightMachineStatus() {
        LightMachineStatusCharacteristics lightMachineStatusCharacteristics = this.lightService.getLightMachineStatusCharacteristics();
        if (lightMachineStatusCharacteristics != null) {
            return lightMachineStatusCharacteristics.read();
        }
        return false;
    }

    @Override
    public MutableStateFlow<LightMachineStatus> getLightMachineStatusFlow() {
        LightMachineStatusCharacteristics lightMachineStatusCharacteristics = this.lightService.getLightMachineStatusCharacteristics();
        if (lightMachineStatusCharacteristics != null) {
            return lightMachineStatusCharacteristics.getLightMachineStatus();
        }
        return null;
    }

    @Override
    public void setInitDoneCallBack(Function0<Unit> callback) {
        Intrinsics.checkNotNullParameter(callback, "callback");
        setInitializeCallBack(callback);
    }

    @Override
    public void clearDoneCallBack() {
        setInitializeCallBack(null);
    }

    @Override
    public void requestControl(Function0<Unit> successCallback, Function0<Unit> failedCallback) {
        Intrinsics.checkNotNullParameter(successCallback, "successCallback");
        Intrinsics.checkNotNullParameter(failedCallback, "failedCallback");
//        executeRequest(new LightControlPointRequest(LightControlPointOpCode.requestControl, null, 2, null), new LightDevice$requestControl$1(successCallback, failedCallback));
    }

    @Override
    public void setLightMode(LightMode lightMode, Function0<Unit> successCallback, Function0<Unit> failedCallback) {
        Intrinsics.checkNotNullParameter(lightMode, "lightMode");
        Intrinsics.checkNotNullParameter(successCallback, "successCallback");
        Intrinsics.checkNotNullParameter(failedCallback, "failedCallback");
//        executeRequest(new LightControlPointRequest(LightControlPointOpCode.setLightMode, ByteBuffer.allocate(1).order(ByteOrder.LITTLE_ENDIAN).put(UByte.m2872constructorimpl((byte) lightMode.getRaw())).array()), new LightDevice$setLightMode$1(successCallback, failedCallback));

    }

    @Override
    public void setLightIntensity(int i, Function0<Unit> successCallback, Function0<Unit> failedCallback) {
        Intrinsics.checkNotNullParameter(successCallback, "successCallback");
        Intrinsics.checkNotNullParameter(failedCallback, "failedCallback");
//        executeRequest(new LightControlPointRequest(LightControlPointOpCode.setLightIntensity, ByteBuffer.allocate(1).order(ByteOrder.LITTLE_ENDIAN).put(UByte.m2872constructorimpl((byte) i)).array()), new LightDevice$setLightIntensity$1(successCallback, failedCallback));
    }

    @Override
    public void setLightBeam(LightBeamMode lightBeamMode, Function0<Unit> successCallback, Function0<Unit> failedCallback) {
        Intrinsics.checkNotNullParameter(lightBeamMode, "lightBeamMode");
        Intrinsics.checkNotNullParameter(successCallback, "successCallback");
        Intrinsics.checkNotNullParameter(failedCallback, "failedCallback");
//        executeRequest(new LightControlPointRequest(LightControlPointOpCode.setLightBeamMode, ByteBuffer.allocate(1).order(ByteOrder.LITTLE_ENDIAN).put(UByte.m2872constructorimpl((byte) lightBeamMode.getRaw())).array()), new LightDevice$setLightBeam$1(successCallback, failedCallback));
    }

    @Override
    public MutableStateFlow<BatteryStatus> getBatteryStatusFlow() {
        BatteryStatusCharacteristic batteryStatusCharacteristic = this.batteryService.getBatteryStatusCharacteristic();
        if (batteryStatusCharacteristic != null) {
            return batteryStatusCharacteristic.getBatteryStatus();
        }
        return null;
    }

    @Override
    public int getBattery() {
        return super.getBattery();
    }
}
